home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / NextAnswers / 1429_class_variables.rtf < prev    next >
Text File  |  1993-11-08  |  2KB  |  26 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f3\fmodern Ohlfs;}
  2. \paperw11300
  3. \paperh7340
  4. \margl120
  5. \margr120
  6. {\colortbl;\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ulnone\fs28\fc0\cf0 Q:  Does Objective-C have any concept of class variables—variables managed by the class object like those in SmallTalk?\
  8. \
  9. A:  
  10. \fc1\cf1 In Objective-C the class object has no variables.  Objective-C provides only internal data structures for the class, none that you can set or access directly.  The class object also has no access to any instance variable; it can't initialize, read, or alter them.\
  11. \
  12. Therefore, for all the instances of a class to share data, an external variable of some sort is required.  Some classes declare static variables and provide class methods to manage them.  Declaring a variable static in the same file as the class definition limits its scope to just the class—and to just the part of the class that's implemented in the file.  Unlike instance variables, static variables are not visible to subclasses or categories of the class.\
  13. \
  14. Static variables help give the class object more functionality than just that of a “factory” producing instances; it can approach being a complete and versatile object in its own right.  A class object can be used to coordinate the instances it creates, allocate instances from lists of objects already created, or manage other processes essential to the class.  \
  15. \
  16.  
  17. \fc0\cf0 You can use the 
  18. \b +initialize 
  19. \b0 method to set up and initialize class variables and you can provide class methods to set/retrieve the variables.  See also one of the examples in Release 2 (/NextDeveloper/Examples/SortingInAction) which uses this strategy to share one mutex variable across many instances of a class.\
  20. \
  21. QA708\
  22. \
  23. Valid for 1.0, 2.0, 3.0\
  24. \
  25.  
  26.